/**
 * Description: 
 * File: a.c |Time: 2021-07-20 16:09
 */
#include <stdio.h>

union  {
    int i;
    char x[2];
}a;

void print_bin(int x)
{
    int arr_size = sizeof(int) * 8;
    char arr[sizeof(int) * 8] = {0};
    unsigned int tmp = 1;
    int i;

    for (i = 0; i < arr_size; i++) 
    {
        if ((tmp & x) == tmp) 
        {
            arr[i] = '1';
        }
        else
        {
            arr[i] = '0';
        }

        tmp = tmp << 1;
    }

    for (i = 0; i < arr_size; i++) 
    {
        printf("%c", arr[arr_size - 1 - i]);

        if ((i + 1) % 4 == 0) 
        {
            putchar(' ');
        }
    }

    printf("\n");

}


int main(int argc, const char *argv[])
{
   a.x[0]  = 10;
   a.x[1] = 1;

    printf("u_a.x = %d\n", a.i);
    printf("u_a.x = %#x\n", a.i);

    print_bin(a.i);

    return 0;
}
